/**
* Result.java 2020/5/9 5:23 下午
* Copyright ©2020 www.bmsoft.com.cn All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package common.model;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Future;
import java.util.function.BiConsumer;

/**
 * File：Result.java<br>
 * Title: <br>
 * Description: <br>
 * Company: www.treefinance.com.cn <br>
 * @author heyouchi
 * Date: 2020/5/9
 */
public interface Result extends CompletionStage<Result>, Future<Result>, Serializable {

  Object getValue();

  void setValue(Object value);

  Throwable getException();

  void setException(Throwable t);

  boolean hasException();

  Object recreate() throws Throwable;

  Map<String, String> getAttachments();

  void addAttachments(Map<String, String> map);

  void setAttachments(Map<String, String> map);

  String getAttachment(String key);

  String getAttachment(String key, String defaultValue);

  void setAttachment(String key, String value);

  Result getNow(Result valueIfAbsent);

  Result whenCompleteWithContext(BiConsumer<Result, Throwable> fn);

  default CompletableFuture<Result> completionFuture() {
    return toCompletableFuture();
  }
}
